package 线程.day3.demo7;

import java.util.concurrent.CountDownLatch;

public class CasTest {
    public static void main(String[] args)throws Exception {
        CountDownLatch cd=new CountDownLatch(2);
        Count c=new Count();
        Thread add=new Thread("add"){
            @Override
            public void run() {
                for(int i=0;i<1000;i++){
                    c.add();
                }
                cd.countDown();
            }
        };

        Thread dec=new Thread("dec"){
            @Override
            public void run() {
                for(int i=0;i<1000;i++){
                    c.dec();
                }
                cd.countDown();
            }
        };

        add.start();
        dec.start();
        //方法一
        //Thread.sleep(10);
        //方法二
//        add.join();
//        dec.join();
        //方法三
        cd.await();
        System.out.println(c.i);
    }
}
